﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThaireInvestmentWeb.Util;
using ThaireInvestmentWeb.WcfSerivce;

namespace ThaireInvestmentWeb.Models
{
    public class ManageEquityModel
    {
         public SearchEquityFilter SearchFilter { get; set; }
         public ManageEquityModel()
        {
            Init();
        }
        void Init()
        {
            CompanyList = new List<SelectListItem> { WebUtil.SelectListSelectDefault() };
            BrokerList = new List<SelectListItem> { WebUtil.SelectListAllDefault() };
            TypeList = new List<SelectListItem> { WebUtil.SelectListAllDefault() };

            if (SearchFilter == null)
                SearchFilter = new SearchEquityFilter();

            if (_data != null)
            {
                foreach (var item in _data.Companies)
                {
                    CompanyList.Add(new SelectListItem() { Text = item.CompanyNameTh, Value = item.CompanyId.ToString() });
                }
                foreach (var item in _data.Brokers)
                {
                    BrokerList.Add(new SelectListItem() { Text = item.BrokerNameEn, Value = item.BrokerId.ToString() });
                }
                foreach (var item in _data.EquityType)
                {
                    TypeList.Add(new SelectListItem() { Text = item.ValueEN, Value = item.ID.ToString() });
                }
            }
        }
        public void ClearFilterAndData()
        {
            Init();
        }

        static EquityHeaderScreenData _data;

        public static ManageEquityModel BuildModel(EquityHeaderScreenData data)
        {
            _data = data;
            return new ManageEquityModel();
        }

        [Required(ErrorMessage = "โปรดระบุ")]
        public int? SelectedCompany
        {
            get { return SearchFilter.Company; }
            set { SearchFilter.Company = value; }
        }
        public IList<SelectListItem> CompanyList { get; set; }

        public int? SelectedType
        {
            get { return SearchFilter.Type; }
            set { SearchFilter.Type = value; }
        }
        public IList<SelectListItem> TypeList { get; set; }

        public int? SelectedBroker
        {
            get { return SearchFilter.Broker; }
            set { SearchFilter.Broker = value; }
        }
        public IList<SelectListItem> BrokerList { get; set; }

        public string Symbol
        {
            get { return SearchFilter.Symbol; }
            set { SearchFilter.Symbol = value; }
        }
        /// <summary>
        /// FullName(EN)
        /// </summary>
        public string FullName
        {
            get { return SearchFilter.FullName; }
            set { SearchFilter.FullName = value; }
        }


        public IList<EquityHeader> Result { get; set; }

        public String SearchBtn { get; set; }
        public String ResetBtn { get; set; }
    }
}